/**
 * 
 */
package com.fwzc.giuseppe.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fwzc.giuseppe.R;
import com.fwzc.giuseppe.base.BaseActivity;

/**
 * 
 * 类名称：UpdateSexuality 类描述： 创建人：何琳 创建时间：2015年6月17日 下午2:01:50
 * 
 * @version
 * 
 */
public class UpdateSexualityActivity extends BaseActivity implements
		OnClickListener {

	private TextView b, g;// 男，女
	private ImageView sex_choose1, sex_choose2;// 选中图片
	private RelativeLayout boy, girl;
	String sex;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_edit_sex);

		initBar();
		initHeadView();//title设置
		initView();
		initMainData();
	}

	/**
	 * 
	 */
	private void initView() {

		b = (TextView) findViewById(R.id.boy);
		g = (TextView) findViewById(R.id.girl);

		sex_choose1 = (ImageView) findViewById(R.id.sex_choose1);
		sex_choose2 = (ImageView) findViewById(R.id.sex_choose2);

		boy = (RelativeLayout) findViewById(R.id.re_boy);
		girl = (RelativeLayout) findViewById(R.id.re_girl);

		boy.setOnClickListener(this);
		girl.setOnClickListener(this);

	}

	/**
	 * 
	 */
	private void initMainData() {
		if (this.getIntent().getStringExtra("sexuality_value").toString()
				.equals(b.getText().toString())) {
			b.setTextColor(getResources().getColor(R.color.red_fe));
			sex_choose1.setVisibility(View.VISIBLE);
			// 以下不选中
			g.setTextColor(getResources().getColor(R.color.black_41));
			sex_choose2.setVisibility(View.INVISIBLE);
		} else if (this.getIntent().getStringExtra("sexuality_value")
				.toString().equals(g.getText().toString())) {
			g.setTextColor(getResources().getColor(R.color.red_fe));
			sex_choose2.setVisibility(View.VISIBLE);
			// 以下不选中
			b.setTextColor(getResources().getColor(R.color.black_41));
			sex_choose1.setVisibility(View.INVISIBLE);
		}
	}

	/**
	 * 
	 */
	private void initHeadView() {
		actionbar_side_name.setText(this.getIntent().getStringExtra(
				"sexuality_title"));
		iv_actionbar_side_left.setVisibility(View.VISIBLE);
		tv_actionbar_side_right.setVisibility(View.VISIBLE);
		tv_actionbar_side_right.setText("保存");
		tv_actionbar_side_right.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				checkSubmit();
			}
		});
	}

	@Override
	public void onClick(View v) {
		if (v == boy) {
			b.setTextColor(getResources().getColor(R.color.red_fe));
			sex_choose1.setVisibility(View.VISIBLE);
			sex = b.getText().toString().trim();
			// 以下不选中
			g.setTextColor(getResources().getColor(R.color.black_41));
			sex_choose2.setVisibility(View.INVISIBLE);
		} else if (v == girl) {
			g.setTextColor(getResources().getColor(R.color.red_fe));
			sex_choose2.setVisibility(View.VISIBLE);
			sex = g.getText().toString().trim();
			// 以下不选中
			b.setTextColor(getResources().getColor(R.color.black_41));
			sex_choose1.setVisibility(View.INVISIBLE);
		} else {
			sex = this.getIntent().getStringExtra("sexuality_value").toString()
					.trim();
		}

	}

	private void checkSubmit() {
		Intent intent = this.getIntent();
		intent.putExtra("sexuality_value", sex);
		setResult(RESULT_OK, intent);
		finish();
	}

}
